﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class control_Star : System.Web.UI.UserControl
{
    //分数
    //int score;
    public int Score
    {
        get { return Int32.Parse(scoreTextBox.Text); }
        set { scoreTextBox.Text = value.ToString(); }
    }
    //public int Score
    //{
    //    get { return score;}
    //}
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 初始化打分界面
    /// </summary>
    /// <param name="starNumber">显示星星的数目</param>
    /// <param name="score">打的分数</param>
    /// <param name="isReadOnly">点击后是否改变分数</param>
    public void initial(int starNumber, int score, bool isReadOnly)
    {
        scoreTextBox.Text = score.ToString();
        if (isReadOnly)
        {
            this.scoreTextBox.Enabled = !isReadOnly;
        }
        //this.placeHolder.Controls.Clear();
        //for (int i = 0; i < score; i++)
        //{
        //    ImageButton s = new ImageButton();
        //    s.Width = 30;
        //    s.Height = 30;
        //    s.ImageUrl = "~/images/orangeBall.png";
        //    if (!isReadOnly)
        //    {
        //        s.Click += new ImageClickEventHandler(s_Click);
        //    }
        //    else
        //    {
        //        s.Enabled = false;
        //    }
        //    this.placeHolder.Controls.Add(s);
        //}
        //for (int i = score; i < starNumber; i++)
        //{
        //    ImageButton s = new ImageButton();
        //    s.Width = 30;
        //    s.Height = 30;
        //    s.ImageUrl = "~/images/blueBall.png";
        //    if (!isReadOnly)
        //    {
        //        s.Click += new ImageClickEventHandler(s_Click);
        //    }
        //    else
        //    {
        //        s.Enabled = false;
        //    }
        //    this.placeHolder.Controls.Add(s);
        //}
    }
    //打分后事件处理
    public void s_Click(object sender, ImageClickEventArgs e)
    {
        //ImageButton s = (ImageButton)sender;
        //int index = this.placeHolder.Controls.IndexOf(s);
        //score = index + 1;
        //for (int i = 0; i <=  index; i++)
        //{
        //    ImageButton b = (ImageButton)this.placeHolder.Controls[i];
        //    b.ImageUrl = "~/images/orangeBall.png";
        //}
        //for (int i = index +　1; i < this.placeHolder.Controls.Count; i++)
        //{
        //    ImageButton b = (ImageButton)this.placeHolder.Controls[i];
        //    b.ImageUrl = "~/images/blueBall.png";
        //}
    }
}